<?php

class ScoreManager_AverageController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {
        $this->view->yearSemester = $this->getRequest()->getPost('yearSemester');
        $this->view->selectGrade = $this->getRequest()->getPost('select-grade');

        // 考試設定
        if ( $this->view->yearSemester and $this->view->selectGrade) {
            $tempArr = explode("-",$this->view->yearSemester);
            $year = (int) $tempArr[0];
            $semester = (int)$tempArr[1];
            $grade = (int)$this->view->selectGrade;
            $examine = new Semester_Model_SemesterExamine();
            $examineSet = $examine->getExaminSet($year, $semester, $grade);
            // 考試設定
            $this->view->examineSet = $examineSet;
        }
        $stage = (int)$this->_getParam('stage');
        if ($stage) {
            // 階段別
            $this->view->stage = $stage;
              // 取出班級階段成績資料
            $statistics = new Score_Model_Statistics($grade, $this->view->yearSemester,$stage);
             // 課程名稱
            $this->view->subject = $statistics->getSubject();
            // 記錄選取科目
            $this->view->selSubject = $this->_getParam('selSubject');
         // 加計平時成績
            $this->view->plusCount = (int)$this->_getParam('plusCount');

            // 記錄選取班級
            $this->view->selClass = $this->_getParam('selClass');
            $this->view->showRank = $this->_getParam('showRank');
            $semesterClass = new Semester_Model_SemesterClass();
            $this->view->className = $semesterClass->getGradeClassNames($year, $semester, $grade);
        }
        // 計算平均
        if ($this->_getParam('act') == 'count') {
           $res = $statistics->getAverageScore($stage,
                $this->view->selSubject,
                $this->view->plusCount );
                $this->view->averageList = $res;
        }

    }


}

